package com.qidi.ssh.service;

import com.qidi.ssh.bean.User;
import com.qidi.ssh.dao.UserDao;
import com.qidi.ssh.utils.MD5Utils;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author zhouXinBin
 * @create 2020-10-16-11:58
 */
@Transactional
public class UserServiceimpl implements UserService {
    private UserDao userDao;

    public void setUserDao(UserDao userDao) {
        this.userDao = userDao;
    }

    @Override
    public boolean regist(User user) {
        User user1 = userDao.checkUserByUsername(user.getUser_code());
        if (user1==null){
            user.setUser_password(MD5Utils.md5(user.getUser_password()));
            user.setUser_state("1");
            userDao.save(user);
            return true;
        }
        return false;
    }

    @Override
    public User login(User user) {
        user.setUser_password(MD5Utils.md5(user.getUser_password()));
        User user1 = userDao.getUserByCodeAndPassword(user);
        return user1;
    }

    @Override
    public List<User> findAllUser() {
        return userDao.findAll();
    }
}
